package com.github.yoojia.flow.support;

import com.github.yoojia.flow.Context;
import com.github.yoojia.flow.Event;
import com.github.yoojia.flow.EventInterceptor;
import com.github.yoojia.flow.InitialContext;

/**
 * @author 陈小锅 (yoojiachen@gmail.com)
 * @since 1.0.0
 */
public abstract class CheckedEventInterceptor extends InitialContext implements EventInterceptor {

    @Override
    final public boolean onInterceptEvent(Context context, Event event) {
        return onIfAcceptEvent(event) &&
                onInterceptEventImpl(context, event);
    }

    /**
     * 检查Event是否接受处理，由onHandleEvent方法处理。
     *
     * @param event Event
     * @return 接受处理，则执行 onFilterEvent 方法。
     */
    protected abstract boolean onIfAcceptEvent(Event event);

    /**
     * 处理Event对象
     *
     * @param context Context引用
     * @param event   Event
     * @return 返回拦截处理结果
     */
    protected abstract boolean onInterceptEventImpl(Context context, Event event);

}
